home *** CD-ROM | disk | FTP | other *** search
- /*
- File: MissingLibraryRoutines.c
-
- Contains: Implementation of routines missing from InterfaceLib.
-
- Written by: Quinn "The Eskimo!"
-
- Copyright: © 1997 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
- */
-
- #include <Types.h>
-
- // This file contains implementations of various Mac OS API routines
- // that were never rolled in to InterfaceLib. As a result, these
- // routines can be called from classic 68K clients, but not from
- // CFM-68K or CFM-PPC clients.
-
- extern pascal SInt16 LMGetUnitTableEntryCount(void)
- // Get the value from low memory directly.
- {
- return *((SInt16 *) 0x01d2);
- }
-
- extern pascal void LMSetUnitTableEntryCount(SInt16 value)
- // Put the value into low memory directly.
- {
- *((SInt16 *) 0x01d2) = value;
- }
-
- // DriverInstallReserveMem is a bit trickier to implement that the
- // previous two routines. Basically we have get the address of the
- // _DriverInstall ($A03D) trap and then call it using
- // CallOSTrapUniversalProc. There are a number of important things
- // to note here:
- // a) We can just get the trap address and treat it as a UPP.
- // The trap tables are defined to contain UPPs, either pointers
- // to real 68K code, or pointers to a routine descriptor (if
- // the trap is native or fat).
- // b) We must use CallOSTrapUniversalProc, not CallUniversalProc.
- // CallOSTrapUniversalProc automatically does a number of things
- // that are very critical for call OS traps. See "IM:PowerPC
- // System Software", p2-42 for a full description.
- // c) When calling OS traps from PPC, it's important to get the
- // ProcInfo right. Specifically, all OS traps assume an
- // implicit parameter of D1 as the first parameter. After
- // that, the parameters should be defined in the order that
- // they are declared in the prototype. If you fail to get
- // the order right, or to put D1 first, your code will work,
- // up until it encounters someone who has patched the OS trap
- // with a native or fat patch. Then strange things will happen,
- // and you'll spend hours in MacsBug trying to figure it out.
-
- // The trap number and ProcInfo description for DriverInstallReserveMem.
-
- enum {
- _DriverInstallReserveMem = 0x0A43D
- };
-
- enum {
- uppDriverInstallProcInfo = kRegisterBased
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | REGISTER_ROUTINE_PARAMETER(1, kRegisterD1, SIZE_CODE(sizeof(short)))
- | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(DRVRHeaderPtr)))
- | REGISTER_ROUTINE_PARAMETER(3, kRegisterD0, SIZE_CODE(sizeof(short)))
- };
-
- extern pascal OSErr DriverInstallReserveMem(DRVRHeaderPtr drvrPtr, short refNum)
- {
- UniversalProcPtr trapAddress;
-
- // Check that I've got the ProcInfo correct.
- if (false) {
- if ( uppDriverInstallProcInfo != 0x00533022) {
- DebugStr("\pDriverInstallReserveMem: uppDriverInstallProcInfo is not what it should be.");
- }
- }
-
- trapAddress = (UniversalProcPtr) GetOSTrapAddress(_DriverInstallReserveMem);
- return CallOSTrapUniversalProc(trapAddress, uppDriverInstallProcInfo, _DriverInstallReserveMem, drvrPtr, refNum);
- }
-